<template>
  <view>
    <cu-custom bgColor="" :isBack="true" bgColor="bg-white">
      <view slot="backText">返回</view>
      <view slot="content">阵旗升级</view>
    </cu-custom>
    <ad unit-id="adunit-fa0a75a672d290fa" ad-type="video" ad-theme="white"></ad>

    <view class="margin-top card">
      <view class="cu-form-group">
        <view class="title">当前等级</view>
        <input type="number" v-model="level_now" placeholder="请输入当前阵旗等级"></input>
      </view>
      <view class="cu-form-group">
        <view class="title">提升等级</view>
        <input type="number" disabled="true" :value="level_now > 0 ? level_now * 1 + 1 : ''"
               placeholder="你想提升到多少级?"></input>
      </view>
      <view class="cu-form-group">
        <view class="title">阵旗强化</view>
        <input type="number" v-model="intensify_now_number" placeholder="你目前拥有的阵旗强化令数"></input>
      </view>
      <view class="cu-form-group">
        <view class="title">同名阵旗</view>
        <input type="number" v-model="flag_now_number" placeholder="你目前拥有的同名阵旗数"></input>
      </view>
      <view class="cu-form-group">
        <view class="title">阵旗精华</view>
        <input type="number" v-model="essence_now_number" placeholder="你目前拥有的阵旗精华数"></input>
        <button class="cu-btn bg-green shadow" @click="calc">Go!</button>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        level_now: "",
        intensify_now_number: "",
        flag_now_number: "",
        essence_now_number: "",
        intensify_number: [0, 20, 30, 40, 50, 65, 80, 95, 110, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2150, 2300, 2450, 2600, 2750, 2900, 3050, 3200, 3350, 3500, 3650, 3800, 3950, 4100, 4250, 3750, 3750, 3750, 3750, 3750, 3750, 3750, 3750, 3750, 3750],
        sum: 0
      }
    },
    onLoad() {
    },
    methods: {
      calc() {
        if (!this.level_now) {
          uni.showToast({
            title: "你是不是闲得慌? 输入呀~",
            icon: "none"
          })
          return
        }
        if (this.level_now >= 60) {
          uni.showToast({
            title: "兄得, 我只能算60级以内的加减法哦~",
            icon: "none"
          })
          return
        }
        let start = this.level_now
        let end = this.level_now * 1 + 1
        let arr = this.intensify_number.slice(start, end)
        let flag_num = 0
        let essence_numebr = 0
        if (end == 5 || end == 10 || end == 15 || end == 20 || end == 30 || end == 35 || end == 45 || end == 50 || end == 55 || end == 60) {
          flag_num = end / 5
          if (end == 55) {
            essence_numebr = 125
          } else if (end == 60) {
            essence_numebr = 250
          }
        }

        this.sum = 0
        for (let i = 0; i < arr.length; i++) {
          this.sum += arr[i]
        }
        uni.showModal({
          title: "小伙子",
          content: `你从${start}级升到${end}级, ${this.sum - this.intensify_now_number >= 0 ? "还需要" + (this.sum - this.intensify_now_number) + "个阵旗强化令" : "阵旗强化令多了" + Math.abs(this.sum - this.intensify_now_number) + "个"} , ${flag_num - this.flag_now_number >= 0 ? "还需要" + (flag_num - this.flag_now_number) + "个同名阵旗" : "同名阵旗多了" + Math.abs(flag_num - this.flag_now_number) + "个"}, ${essence_numebr - this.essence_now_number >= 0 ? "还需要" + (essence_numebr - this.essence_now_number) + "阵旗精华" : "阵旗精华多了" + Math.abs(essence_numebr - this.essence_now_number) + "个"}`,
          showCancel: false,
          success: (res) => {
            if (res.confirm) {
              this.level_now = ""
              this.intensify_now_number = ""
              this.flag_now_number = ""
              this.essence_now_number = ""
            }
          }
        })
      }
    }
  }
</script>

<style scoped>
  .card {
    background-image: url('https://mmbiz.qpic.cn/mmbiz_jpg/8iaIEbCVSqJamMekDm3yDLBkjPpxVuuTA5xvriaHZXSV3ick4kl4icVz00dGwgbjicIjv6c0YZRhdL5OCaHicNwXVR9A/640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1&wx_co=1');
    background-size: cover;
    background-position: center center;
  }

  .cu-form-group {
    background-color: rgba(255, 255, 255, 0.8);
  }
</style>
